package cc.laop.mq.kafka.producer;

import org.apache.kafka.clients.producer.RecordMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Pengpeng on 2017/5/26.
 */
public class ProducerListener implements org.springframework.kafka.support.ProducerListener {

    private static final Logger logger = LoggerFactory.getLogger(ProducerListener.class);

    /*
    * 发送成功后调用
    * */
    @Override
    public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) {
        logger.info("Success. topic: {}, partition: {}, Key: {}, value: {}", new Object[]{topic, partition, key, value});
    }

    /*
    * 发送失败调用
    * */
    @Override
    public void onError(String topic, Integer partition, Object key, Object value, Exception e) {
        logger.info("Error. topic: {}, partition: {}, Key: {}, value: {}", new Object[]{topic, partition, key, value});
    }


    /*
    * 是否启动监听
    * */
    @Override
    public boolean isInterestedInSuccess() {
        return true;
    }
}
